import { ref } from "vue";
import type { Ref } from "vue";
import { defineStore } from "pinia";
import { fetchRecommendListAPI } from "@/api/recommendAPI";
import type { RecommendDTO, RecommendVO } from "@/types/recommendType";

const useRecommendStore = defineStore("recommendStore", () => {
   // 推荐信息
   const recommendInfo: Ref<RecommendVO> = ref<RecommendVO>({} as RecommendVO);

   // 发送请求推荐信息的回调函数
   const fetchRecommendInfo = async (url: string, data: RecommendDTO):Promise<void> => {
      try {
         const { result }: { result: RecommendVO } = await fetchRecommendListAPI(url, data);
         recommendInfo.value = result;
      } catch (error: any) {
         await error;
      }
   };
   return {
      recommendInfo,
      fetchRecommendInfo,
   };
});


export default useRecommendStore;